public class StringSynapse : CharSynapse
{
    public bool CreateFromString(string a_pShareName, string a_pStringIn)
    {
        sbyte[] bs = new sbyte[a_pStringIn.Length+1];
        for (int i = 0; i < a_pStringIn.Length; i++)
        {
            bs[i] = (sbyte)a_pStringIn[i];
        }
        bs[a_pStringIn.Length] = 0;
        return CreateFromArray(a_pShareName, bs.Length, bs);
    }

    public bool WriteStringNow(string s)
    {
        int size;
        if (Size() > s.Length)
        {
            size = s.Length;
        }
        else
        {
            size = Size() - 1;
        }
        sbyte[] bs = new sbyte[size+1];
        for (int i = 0; i < size; i++)
        {
            bs[i] = (sbyte)s[i];
        }
        bs[size] = 0;
        return WriteArrayNow(bs, (int)bs.Length);
    }

    public string ReadStringNow()
    {
        sbyte[] rb = new sbyte[Size()];
        ReadArrayNow(rb);
        for (int i = 0; i < Size(); i++)
        {
            if (rb[i] == 0)
            {
                char[] c = new char[i];
                for (int j = i - 1; j >= 0; j--)
                {
                    c[j] = (char)rb[j];
                }
                return new string(c);
            }
        }
        return "";
    }

    public void WriteString(string s)
    {
        int size;
        if (Size() > s.Length)
        {
            size = s.Length;
        }
        else
        {
            size = Size() - 1;
        }
        sbyte[] bs = new sbyte[size + 1];
        for (int i = 0; i < size; i++)
        {
            bs[i] = (sbyte)s[i];
        }
        bs[size] = 0;
        WriteArray(bs, (int)bs.Length);
    }

    public void ProtectWriteString(string s)
    {
        int size;
        if (Size() > s.Length)
        {
            size = s.Length;
        }
        else
        {
            size = Size() - 1;
        }
        sbyte[] bs = new sbyte[size + 1];
        for (int i = 0; i < size; i++)
        {
            bs[i] = (sbyte)s[i];
        }
        bs[size] = 0;
        ProtectWriteArray(bs, (int)bs.Length);
    }

    public string ReadString()
    {
        sbyte[] rb = new sbyte[Size()];
        ReadArray(rb);
        for (int i = 0; i < Size(); i++)
        {
            if (rb[i] == 0)
            {
                char[] c = new char[i];
                for (int j = i - 1; j >= 0; j--)
                {
                    c[j] = (char)rb[j];
                }
                return new string(c);
            }
        }
        return "";
    }

    public void WriteStringWhenOld(string s)
    {
        int size;
        if (Size() > s.Length)
        {
            size = s.Length;
        }
        else
        {
            size = Size() - 1;
        }
        sbyte[] bs = new sbyte[size + 1];
        for (int i = 0; i < size; i++)
        {
            bs[i] = (sbyte)s[i];
        }
        bs[size] = 0;
        WriteArrayWhenOld(bs, (int)bs.Length);
    }

    public string ReadStringWhenNew()
    {
        sbyte[] rb = new sbyte[Size()];
        ReadArrayWhenNew(rb);
        for (int i = 0; i < Size(); i++)
        {
            if (rb[i] == 0)
            {
                char[] c = new char[i];
                for (int j = i - 1; j >= 0; j--)
                {
                    c[j] = (char)rb[j];
                }
                return new string(c);
            }
        }
        return "";
    }
}